from django.shortcuts import render

# Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from userapp.ser import *


class Test(APIView):
    def get(self,request):
        return Response('ok')


class Register(APIView):
    """
    注册
    :param request:
    :param args:
    :param kwargs:
    :return:
    """

    def post(self, request):
        data = request.data
        user_ser = UserSerializer(data=data)
        try:
            user_ser.is_valid()
            user_ser.save()
            return Response({'code': 200, 'msg': '注册成功'})
        except Exception as e:
            print(e)
            return Response({'code': 500, 'msg': '注册失败，此用户名已被注册'})






